from common.base_model import BaseModel, BasicModelMixin, CompanyMixin, \
    CreateMixin, UpdateMixin, DeleteMixin
from exts import db
from common import constant

MIDDLE_DB_STR_LEN = constant.MIDDLE_DB_STR_LEN
LONG_DB_STR_LEN = constant.LONG_DB_STR_LEN


class File(BasicModelMixin, db.Model, CompanyMixin, CreateMixin, UpdateMixin):
    __tablename__ = 'file'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(constant.MIDDLE_DB_STR_LEN))
    file_path = db.Column(db.String(constant.LONG_DB_STR_LEN), nullable=False)
    file_type = db.Column(db.Integer, nullable=False,
                          default=constant.FileType.IMG)
    img_type = db.Column(db.Integer,
                         default=constant.ImgType.GALLERY)
    file_size = db.Column(db.BigInteger, default=0, server_default='0')


# # 商品单品等图片
# class ObjToFile(db.Model, BasicModelMixin, CompanyMixin, CreateMixin, UpdateMixin, DeleteMixin):
#     __tablename__ = 'obj_to_file'
#
#     obj_id = db.Column(db.Integer)
#     obj_type = db.Column(db.String(constant.MIDDLE_DB_STR_LEN),
#                          default=constant.FileBelongType.SPU)
#     file_id = db.Column(db.Integer, db.ForeignKey('file.id'), primary_key=True)


# 图片关联
class FileRelation(db.Model, BasicModelMixin,
                   CompanyMixin, CreateMixin, UpdateMixin, DeleteMixin):
    """"""
    __tablename__ = 'file_relation'

    id = db.Column(db.Integer, primary_key=True)
    file_id = db.Column(db.Integer, db.ForeignKey('file.id'), nullable=False)
    belong_id = db.Column(db.Integer, nullable=False)
    belong_type = db.Column(db.String(MIDDLE_DB_STR_LEN), nullable=False,
                            default=constant.FileBelongType.SPU)
